<template>
<div>
  <el-card class="box-card">
    <div >
    <el-form :model="OrderForm" label-width="70px" >
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="商品名称">
            <el-input v-model="GoodsForm.gname" :disabled="true"  size="small"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="商品库存">
            <el-input v-model="GoodsForm.gnum" :disabled="true" size="small"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="商品单价">
            <el-input v-model="GoodsForm.price" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row></el-row>
      <el-row></el-row>
      <el-row></el-row>
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="购买数量">
            <el-input v-model="OrderForm.num" @blur="getOprice()"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="购买金额">
            <el-input v-model="OrderForm.oprice"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="5">
          <el-form-item label="备注">
            <el-input
              type="textarea"
              autosize
              placeholder="请输入内容"
              v-model="textarea1">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div style="float: left">
      <el-button @click="userFormVisible = false">取 消</el-button>
      <el-button @click="saveOrder()" type="primary">确 定</el-button>
    </div>
    </div>
  </el-card>
</div>
</template>

<script>
    export default {
        name: "AddGoods",
      data(){
          return{
            textarea1:'',
            gid:null,
            GoodsForm:{},
            OrderForm:{oprice:''}
          }
      },
      mounted() {
          debugger;
          this.gid=this.$route.query.id;
          this.getGoods();
      },
      methods:{
          getGoods:function () {
            this.$http.get("/goods/getGoods/"+this.gid).then((res)=>{
              this.GoodsForm=res.data.result;
            })
          },
        getOprice:function () {
          this.OrderForm.oprice=this.OrderForm.num*this.GoodsForm.price;
        },
        saveOrder:function () {
            this.OrderForm.gid=this.gid;
            this.OrderForm.uid=JSON.parse(sessionStorage.getItem("user")).id;
            debugger;
            if(this.OrderForm.num>this.GoodsForm.gnum){
              alert("下单数量不能大于库存数量");
            }else{
              this.$http.post("/order/save",this.OrderForm).then((res)=>{
                if(res.data.success){
                  this.$message.success(res.data.message);
                  this.$router.push("/orderList")
                }else{
                  this.$message.erroe(res.data.message);
                }
              })
          }

        }
      }
    }
</script>

<style scoped>

</style>
